package com.android.jr_infraredcamera

import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment


// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Use the [UsbCameraFragment.newInstance] factory method to
 * create an instance of this fragment.
 */

class UsbCameraFragment:AppCompatActivity(){

}
/*class UsbCameraFragment : CameraFragment() {
    // TODO: Rename and change types of parameters
    private var param1: String? = null
    private var param2: String? = null
    private var mViewBinding: FragmentUsbCameraBinding? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

//    override fun onCreateView(
//        inflater: LayoutInflater, container: ViewGroup?,
//        savedInstanceState: Bundle?,
//    ): View? {
//        // Inflate the layout for this fragment
//        return inflater.inflate(R.layout.fragment_usb_camera, container, false)
//    }

    companion object {
        *//**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment UsbCameraFragment.
         *//*
        // TODO: Rename and change types and number of parameters
        @JvmStatic
        fun newInstance(param1: String, param2: String) = UsbCameraFragment().apply {
            arguments = Bundle().apply {
                putString(ARG_PARAM1, param1)
                putString(ARG_PARAM2, param2)
            }
        }

        private const val TAG = "===UsbCameraFragment==="
    }

    override fun getCameraView(): IAspectRatio? {
        Log.e(TAG, "getCameraView: ============")
//        return AspectRatioTextureView(requireContext())
        return mViewBinding?.tvCameraRender
    }

    override fun getCameraViewContainer(): ViewGroup? {
        Log.e(TAG, "getCameraViewContainer: ========================")
        return mViewBinding?.container
    }

    override fun getRootView(inflater: LayoutInflater, container: ViewGroup?): View? {
        Log.e(TAG, "getRootView: ===================")
        if (mViewBinding == null) {
            mViewBinding = FragmentUsbCameraBinding.inflate(inflater, container, false)
        }
        return mViewBinding?.root
    }


    private var ffmpegInputStream: InputStream? = null
    override fun onCameraState(
        self: MultiCameraClient.ICamera,
        code: ICameraStateCallBack.State,
        msg: String?,
    ) {
        Log.e(TAG, "onCameraState: ===============")
        when (code) {
            ICameraStateCallBack.State.OPENED -> {

                this.addPreviewDataCallBack(object : IPreviewDataCallBack {
                    override fun onPreviewData(
                        data: ByteArray?,
                        width: Int,
                        height: Int,
                        format: IPreviewDataCallBack.DataFormat,
                    ) {
                        //3681287
                          Log.e(TAG, "onPreviewData: ===${data?.size}")



                    }
                })
                Log.e(TAG, "onCameraState: ===OPENED")
            }

            ICameraStateCallBack.State.CLOSED -> {
                Log.e(TAG, "onCameraState: ===CLOSED")
            }

            ICameraStateCallBack.State.ERROR -> {
                Log.e(TAG, "onCameraState: ===ERROR")
            }
        }
    }

    override fun getGravity(): Int = Gravity.CENTER


    override fun initData() {
        super.initData()
        EventBus.with<Int>(BusKey.KEY_FRAME_RATE).observe(this) {
            // Log.e(TAG, "initData: ===frame rate:  $it fps")
        }
    }

    override fun generateCamera(ctx: Context, device: UsbDevice): MultiCameraClient.ICamera {
        Log.e(
            TAG,
            "generateCamera: ====${device.deviceName}==${device.deviceId}==${device.vendorId}==${device.productId}",
        )
        return super.generateCamera(ctx, device)
    }

    override fun getCameraRequest(): CameraRequest {
        Log.e(TAG, "getCameraRequest: ====")
        //return super.getCameraRequest()
        return CameraRequest.Builder()


            //.setRenderMode(CameraRequest.RenderMode.OPENGL) // camera render mode
            //.setDefaultRotateType(RotateType.FLIP_LEFT_RIGHT) // rotate camera image when opengl mode
            .setPreviewWidth(1280) // camera preview width
            .setPreviewHeight(512) // camera preview height
            //.setAudioSource(CameraRequest.AudioSource.SOURCE_AUTO) // set audio source
            //.setPreviewFormat(CameraRequest.PreviewFormat.FORMAT_YUYV) // set preview format, MJPEG recommended
            //.setAspectRatioShow(true) // aspect render,default is true
            //.setCaptureRawImage(false) // capture raw image picture when opengl mode
            //.setRawPreviewData(false)  // preview raw image when opengl mode
            .create()
    }

    override fun getDefaultCamera(): UsbDevice? {
        Log.e(TAG, "getDefaultCamera: ====${super.getDefaultCamera()?.deviceName}")
        return super.getDefaultCamera()
    }

    override fun initView() {
        super.initView()

    }


    override fun onDestroyView() {
        super.onDestroyView()
    }


}*/
